#include <bits/stdc++.h>
using namespace std;
int q[20];

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		q[i] = s[i] - '0';
		if (q[i] >= 5) {
			if (q[i] == 9 && i == 0) {
				q[i] = q[i];
			}else{
				q[i] = 9 - q[i];
			}
		}
	}
	for (int i = 0; i < s.size(); ++i) {
		cout << q[i];
	}
	return 0;
}